<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>办理任务</title>
		<meta name="decorator" content="form"/>
	</head>
	<body>
	<input type="hidden" id="bloodVolume" value="800">
	<input type="hidden" id="nextUsers" value="">
		<div class="main-container" id="main-container">
			<div class="layui-row">
				<div class="layui-col-sm12 toolbar" id="toolBarGrid">
					<div class="pull-left">
						<a href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain " onclick="clickSubmit()">
									<span class="l-btn-left l-btn-icon-left">
										<span class="l-btn-text">办理</span>
										<span class="l-btn-icon icon-reload">&nbsp;</span>
									</span>
						</a>
						<a href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain " onclick="backStartUser()">
									<span class="l-btn-left l-btn-icon-left">
										<span class="l-btn-text">驳回到发起人</span>
										<span class="l-btn-icon icon-reload">&nbsp;</span>
									</span>
						</a>
						<a href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain " onclick="backPrevious()">
									<span class="l-btn-left l-btn-icon-left">
										<span class="l-btn-text">退回上一步</span>
										<span class="l-btn-icon icon-reload">&nbsp;</span>
									</span>
						</a>
						<a href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain " onclick="turnToDo()">
									<span class="l-btn-left l-btn-icon-left">
										<span class="l-btn-text">转办</span>
										<span class="l-btn-icon icon-reload">&nbsp;</span>
									</span>
						</a>
						<a href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain " onclick="backPrevious()">
									<span class="l-btn-left l-btn-icon-left">
										<span class="l-btn-text">跳转</span>
										<span class="l-btn-icon icon-reload">&nbsp;</span>
									</span>
						</a>
					</div>
					<div class="pull-right">
						<a href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain " onclick="closeThisWindow()">
							<span class="l-btn-left l-btn-icon-left">
										<span class="l-btn-text">关 闭</span>
										<span class="l-btn-icon icon-search">&nbsp;</span>
							</span>
						</a>
					</div>
				</div>
			</div>
			<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
				<ul class="layui-tab-title">
					<li  id="busInfo"  class="layui-this" onclick="busInfoClick('${taskDto.actKey}','${flag}')">审批内容</li>
					<li  id="flowInfo">流转信息</li>
				</ul>
				<div class="layui-tab-content" id="tabContent" style="margin-left: 10px">
					<div id="busContent" class="layui-tab-item layui-show"></div>
					<div id="flowContent" class="layui-tab-item"></div>
				</div>
			</div>
		</div>
		<script>
            /**
             * 流程相关信息类
             */
            function processInfo(busId,actKey,taskId,instanceId,defId,flag) {
                this.busId=busId;//业务id
                this.actKey=actKey;//流程key也是业务key
                this.taskId=taskId;//任务id
                this.instanceId=instanceId;//流程实例
                this.defId=defId;//流程定义Id
            }
            var processInfo = new processInfo();
            $(function () {
                var flag = '${flag}';
                if(flag == 1){
                    $("#doTask").remove();
                }
                processInfo.busId='${taskDto.busId}';
                processInfo.actKey='${taskDto.actKey}';
                processInfo.taskId='${taskDto.taskId}';
                processInfo.instanceId='${taskDto.instanceId}';
                processInfo.defId='${taskDto.defId}';
                //获取业务可更改的字段，和流程业务基本信息,和流程节点变量
                processInfo.changeFields= '${changeFields}';
                processInfo.vars='${nextVarNams}';
                $('#busInfo').click();
            });

            /**
             * 业务信息
             */
            function busInfoClick(actKey,flag) {
                var url = "${appPath}/act/busInfo/"+actKey;
                var params = {
                    'busId':processInfo.busId,
                    'taskId':processInfo.taskId,
                    'instanceId':processInfo.instanceId,
                    'defId':processInfo.defId,
                    'flag':flag,
					'orgId':${orgId}
                }
                $.post(url,params,function (r) {
                    $("#busContent").html(r);
                });
            }

            /**
             * 流程信息
             */
            $("#flowInfo").on("click",function () {
                var url = "${appPath}/act/deal/flowInfoHtml";
                var params = {
                    'busId':processInfo.busId,
                    'instanceId':processInfo.instanceId
                }
                $.post(url,params,function (r) {
                    $("#flowContent").html(r);
                });
            })
		</script>

		<script>
            layui.use('element', function(){
                var $ = layui.jquery
                    ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
            });
		</script>
		<script>
            //获取流程下个流向信息
            function getNextNodeInfo() {
                var url ="${appPath}/act/deal/getNextActNodes";
                var params ={
                    'defId':processInfo.defId,
                    'taskId':processInfo.taskId,
                    'varName':processInfo.varName,
                    'varValue':processInfo.varValue
                };
                $.post(url,params,function (result) {
                    if(result.ret == '0'){
                        var nextActNodes=result.extend.nextActNodes;
                        var html='';
                        for (var i=0;i<nextActNodes.length;i++) {
                            var node = nextActNodes[i];
                            if (node.nodeType == '5') {
                                node.nodeName = "结束";
                                processInfo.isSelectUser = false;
                                $("#userTab").remove();
                            }
                        }
                    }else {
                        alertMsg(result.msg);
                    }
                });
            }

            /**
             * 办理
             */
            function clickSubmit() {
                var params ="busId="+processInfo.busId+"&taskId="+processInfo.taskId+"&defId="+processInfo.defId+"&instanceId="+processInfo.instanceId;
                //加入参数可更改的字段数值
                var vars = processInfo.vars;
                var varValue="";
                var varName="";
                if(vars!=null){
                    for(var i=0;i<vars.length;i++){
                        var val=$("#"+vars[i]+"").val();
                        varValue+=val+",";
                        varName+=vars[i]+",";
                    }
                }
                params+="&varName="+varName+"&varValue="+varValue;
                var url="${appPath}/act/deal/toDoActTaskView?"+params;

                //todo 判断是否表单人力资源设定，如果表单指定则不再选择人员
                //弹框层
                layer.open({
                    scrollbar: false,
                    type: 2,
                    title : ["选择下一步审批人" , true],
                    area: ['70%', '70%'], //宽高
                    content: [url,'no'],
                    shadeClose : false,
                });
            }

            /**
             * 转办
             */
            function turnToDo() {
                var params ="busId="+processInfo.busId+"&taskId="+processInfo.taskId+"&defId="+processInfo.defId+"&instanceId="+processInfo.instanceId;
                var url="${appPath}/act/deal/toTurnToDo?"+params;
                //弹框层
                layer.open({
                    scrollbar: false,
                    type: 2,
                    title : ["转办弹框" , true],
                    area: ['70%', '70%'], //宽高
                    content: [url,'no'],
                    shadeClose : false,
                });
            }

            /**
             * 驳回到任务发起人，重新编辑之后再提交
             */
            function backStartUser() {
                var url ="${appPath}/act/deal/backStartUser";
                var params ={
                    'busId':processInfo.busId,
                    'taskId':processInfo.taskId,
                    'instanceId':processInfo.instanceId,
                    'defId':processInfo.defId,
                };
                var fileArr=processInfo.changeFields;
                for(var i=0;i<fileArr.length;i++){
                    var fieldName = fileArr[i];
                    if (fieldName == ''){
                        continue;
                    }
                    //父级搜索表单
                    var fieldValue=$("#"+fieldName+"").val();
                    params[fieldName]=fieldValue;
                }
                var remark = $("#actFieldForm textarea[name='remark']").val();
                params["remark"]=remark;
                $.post(url,params,function (result) {
                    if(result.code == '0'){
                        alert(result,function () {
                            //父级搜索 刷新待办列表
                            $(parent.document.getElementById("main-container")).find("#searchForm").submit();
                            closeThisWindow();

                        });
                    }else {
                        alertMsg(result.msg);
                    }
                });
            }

            /**
             * 退回到上一步
             */
            function backPrevious() {
                alertMsg("该功能开发中,请后续关注");
            }
		</script>
	</body>
</html>